//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_player_name_huddo2.sqf"
#include "x_setup.sqf"

__INC(GVAR(pnhuddo2_frskip));
if (GVAR(pnhuddo2_frskip) == 2) exitWith {
	GVAR(pnhuddo2_frskip) = 0;
};
private ["_ct", "_txtar", "_ctrl", "_pre", "_unc", "_name", "_icon", "_color"];
disableSerialization;
if (!x_show_pname_hud && {!visibleMap}) then {
	_ct = cursorTarget;
	if (!isNull _ct && {_ct isKindOf "CAManBase"} && {alive _ct} && {!GV(player,xr_pluncon)} && {_ct != player} && {((positionCameraToWorld [0,0,0]) distance _ct) <= (GVAR(dist_pname_hud) / 2)} && {side (group _ct) getFriend side (group player) >= 0.6}) then { // && {isPlayer _ct}
		GVAR(pnhuddo2_endtime) = time + 0.8;
		if (!GVAR(showPlayerNameRSC_shown)) then {
			4769 cutRsc [QGVAR(showPlayerNameRsc), "PLAIN"];
			GVAR(showPlayerNameRSC_shown) = true;
			0 spawn FUNC(dosshowhuddo2spawn);
		};
		
		_txtar = [];
		_ctrl = __uiGetVar(GVAR(showPlayerNameRsc1)) displayCtrl 1000;
		_pre = if (group player == group _ct) then {
			_color = [0.9, 0.9, 0.9, 1];
			"*"
		} else {
			_color = [0.6, 0.6, 0.6, 1];
			""
		};
		_unc = _ct getVariable ["xr_pluncon", false];
		_name = if (!_unc) then {if (isPlayer _ct) then {name _ct} else {getText(configFile/"CfgVehicles"/typeOf _ct/"displayName")}} else {GVAR(phud_loc883)};
		_txtar set [count _txtar, _pre + _name];
		_icon = getText(configFile/"CfgVehicles"/typeOf _ct/"Icon");
		if (_icon != "") then {
			_txtar set [count _txtar, image (getText(configFile/"CfgVehicleIcons"/_icon))];
		};
		if (getNumber(configFile/"CfgVehicles"/typeOf player/"attendant") == 1) then {
			_txtar set [count _txtar, lineBreak];
			_txtar set [count _txtar, "Damage: " + str(round ((damage _ct) * 90))];
		};
		_ctrl ctrlSetStructuredText composeText _txtar;
		_ctrl ctrlSetTextColor _color;
	};
} else {
	if (x_show_pname_hud) then {
		["player_hud2"] call FUNC(removePerFrame);
	};
};